import type {
  SearchResult,
  SearchSuggestion,
  TrendingSearch,
  RecommendationResult,
  TrendingContent,
  ContentType,
} from '@/types';

/**
 * 模拟搜索结果数据
 */
export const mockSearchResults: SearchResult[] = [
  {
    id: '1',
    title: 'React 19 新特性详解 - 并发渲染和 Suspense 优化',
    description: 'React 19 带来了许多激动人心的新特性，包括并发渲染、自动批处理、新的 Suspense 功能等。本文将详细介绍这些新特性的使用方法和最佳实践。',
    url: 'https://react.dev/blog/react-19-features',
    thumbnail: 'https://images.unsplash.com/photo-1633356122544-f134324a6cee?w=300&h=200&fit=crop',
    publishDate: new Date('2024-01-15'),
    source: 'React 官方博客',
    author: 'React Team',
    contentType: 'web',
    relevanceScore: 0.95,
    popularity: 8500,
    rating: 4.8,
    language: 'zh-CN',
    tags: ['React', 'JavaScript', '前端开发', '并发渲染'],
    highlights: {
      title: ['React 19', '新特性'],
      description: ['并发渲染', 'Suspense', '最佳实践'],
    },
  },
  {
    id: '2',
    title: 'TypeScript 5.0 完整指南 - 类型系统的重大升级',
    description: 'TypeScript 5.0 版本发布，带来了装饰器、const 断言、模板字面量类型等重要更新。了解如何在项目中使用这些新功能。',
    url: 'https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html',
    thumbnail: 'https://images.unsplash.com/photo-1516116216624-53e697fedbea?w=300&h=200&fit=crop',
    publishDate: new Date('2024-01-10'),
    source: 'TypeScript 官方文档',
    contentType: 'web',
    relevanceScore: 0.92,
    popularity: 7200,
    rating: 4.7,
    language: 'zh-CN',
    tags: ['TypeScript', 'JavaScript', '类型系统', '编程语言'],
    highlights: {
      title: ['TypeScript 5.0', '完整指南'],
      description: ['装饰器', 'const 断言', '模板字面量'],
    },
  },
  {
    id: '3',
    title: 'Vite 构建工具深入解析 - 快速开发的秘密',
    description: 'Vite 作为新一代前端构建工具，以其极快的启动速度和热更新能力受到开发者喜爱。本文深入分析 Vite 的工作原理和优化技巧。',
    url: 'https://vitejs.dev/guide/',
    thumbnail: 'https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=300&h=200&fit=crop',
    publishDate: new Date('2024-01-08'),
    source: 'Vite 官方文档',
    contentType: 'web',
    relevanceScore: 0.88,
    popularity: 6800,
    rating: 4.6,
    language: 'zh-CN',
    tags: ['Vite', '构建工具', '前端开发', '性能优化'],
    highlights: {
      title: ['Vite', '构建工具'],
      description: ['启动速度', '热更新', '工作原理'],
    },
  },
  {
    id: '4',
    title: '现代 CSS 布局技术 - Grid 和 Flexbox 实战',
    description: 'CSS Grid 和 Flexbox 是现代网页布局的核心技术。本教程通过实际案例展示如何使用这些布局技术创建响应式设计。',
    url: 'https://css-tricks.com/snippets/css/complete-guide-grid/',
    thumbnail: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=300&h=200&fit=crop',
    publishDate: new Date('2024-01-05'),
    source: 'CSS-Tricks',
    contentType: 'web',
    relevanceScore: 0.85,
    popularity: 5900,
    rating: 4.5,
    language: 'zh-CN',
    tags: ['CSS', 'Grid', 'Flexbox', '响应式设计'],
    highlights: {
      title: ['CSS', '布局技术'],
      description: ['Grid', 'Flexbox', '响应式设计'],
    },
  },
  {
    id: '5',
    title: 'Web 性能优化最佳实践 - 从加载到渲染',
    description: '网站性能直接影响用户体验和搜索引擎排名。本文介绍从资源加载、代码分割到渲染优化的完整性能优化策略。',
    url: 'https://web.dev/performance/',
    thumbnail: 'https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=300&h=200&fit=crop',
    publishDate: new Date('2024-01-03'),
    source: 'Web.dev',
    contentType: 'web',
    relevanceScore: 0.82,
    popularity: 5400,
    rating: 4.4,
    language: 'zh-CN',
    tags: ['性能优化', 'Web开发', '用户体验', 'SEO'],
    highlights: {
      title: ['性能优化', '最佳实践'],
      description: ['资源加载', '代码分割', '渲染优化'],
    },
  },
];

/**
 * 模拟搜索建议数据
 */
export const mockSearchSuggestions: SearchSuggestion[] = [
  {
    id: '1',
    text: 'React 19 新特性',
    type: 'suggestion',
    frequency: 1250,
    category: '前端开发',
    metadata: {
      popularity: 95,
      resultCount: 8500,
    },
  },
  {
    id: '2',
    text: 'React hooks 使用指南',
    type: 'suggestion',
    frequency: 980,
    category: '前端开发',
    metadata: {
      popularity: 88,
      resultCount: 6200,
    },
  },
  {
    id: '3',
    text: 'React 性能优化',
    type: 'suggestion',
    frequency: 750,
    category: '前端开发',
    metadata: {
      popularity: 82,
      resultCount: 4800,
    },
  },
  {
    id: '4',
    text: 'React 组件设计模式',
    type: 'suggestion',
    frequency: 650,
    category: '前端开发',
    metadata: {
      popularity: 78,
      resultCount: 3900,
    },
  },
  {
    id: '5',
    text: 'React 测试最佳实践',
    type: 'suggestion',
    frequency: 520,
    category: '前端开发',
    metadata: {
      popularity: 72,
      resultCount: 3200,
    },
  },
];

/**
 * 模拟热门搜索数据
 */
export const mockTrendingSearches: TrendingSearch[] = [
  {
    id: '1',
    query: 'ChatGPT 4.0',
    rank: 1,
    growth: 156.8,
    category: '人工智能',
    region: '全球',
    timestamp: Date.now() - 3600000, // 1小时前
  },
  {
    id: '2',
    query: 'React 19',
    rank: 2,
    growth: 89.2,
    category: '前端开发',
    region: '全球',
    timestamp: Date.now() - 7200000, // 2小时前
  },
  {
    id: '3',
    query: 'TypeScript 5.0',
    rank: 3,
    growth: 67.5,
    category: '编程语言',
    region: '全球',
    timestamp: Date.now() - 10800000, // 3小时前
  },
  {
    id: '4',
    query: 'Next.js 14',
    rank: 4,
    growth: 45.3,
    category: '前端框架',
    region: '全球',
    timestamp: Date.now() - 14400000, // 4小时前
  },
  {
    id: '5',
    query: 'Tailwind CSS',
    rank: 5,
    growth: 38.7,
    category: 'CSS框架',
    region: '全球',
    timestamp: Date.now() - 18000000, // 5小时前
  },
];

/**
 * 模拟推荐结果数据
 */
export const mockRecommendationResults: RecommendationResult[] = [
  {
    id: '1',
    type: 'personalized',
    title: 'Vue 3 Composition API 深度解析',
    description: '基于你对 React Hooks 的兴趣，推荐这篇关于 Vue 3 Composition API 的深度文章。',
    url: 'https://vuejs.org/guide/extras/composition-api-faq.html',
    thumbnail: 'https://images.unsplash.com/photo-1593720213428-28a5b9e94613?w=300&h=200&fit=crop',
    contentType: 'web',
    score: 0.92,
    confidence: 0.88,
    reason: '基于你对 React 和现代前端框架的兴趣',
    tags: ['Vue.js', 'Composition API', '前端开发'],
    createdAt: Date.now() - 1800000, // 30分钟前
  },
  {
    id: '2',
    type: 'trending',
    title: 'Svelte 5 发布 - 编译时优化的新突破',
    description: 'Svelte 5 带来了革命性的编译时优化，让前端应用性能达到新高度。',
    url: 'https://svelte.dev/blog/svelte-5-release',
    thumbnail: 'https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=300&h=200&fit=crop',
    contentType: 'web',
    score: 0.89,
    confidence: 0.85,
    reason: '当前热门技术趋势',
    tags: ['Svelte', '编译优化', '前端框架'],
    createdAt: Date.now() - 3600000, // 1小时前
  },
  {
    id: '3',
    type: 'similar',
    title: 'Angular 17 信号系统详解',
    description: '与 React 的状态管理类似，Angular 17 引入了新的信号系统来优化响应式更新。',
    url: 'https://angular.io/guide/signals',
    thumbnail: 'https://images.unsplash.com/photo-1555949963-aa79dcee981c?w=300&h=200&fit=crop',
    contentType: 'web',
    score: 0.86,
    confidence: 0.82,
    reason: '与你查看的 React 状态管理内容相似',
    tags: ['Angular', '信号系统', '状态管理'],
    createdAt: Date.now() - 5400000, // 1.5小时前
  },
];

/**
 * 模拟热门内容数据
 */
export const mockTrendingContent: TrendingContent[] = [
  {
    id: '1',
    title: 'AI 编程助手对比 - GitHub Copilot vs ChatGPT vs Claude',
    description: '详细对比三大 AI 编程助手的功能特点、使用体验和适用场景。',
    url: 'https://example.com/ai-coding-assistants-comparison',
    thumbnail: 'https://images.unsplash.com/photo-1677442136019-21780ecad995?w=300&h=200&fit=crop',
    contentType: 'web',
    category: '人工智能',
    viewCount: 15420,
    shareCount: 892,
    likeCount: 2340,
    trendingScore: 0.95,
    growth: 234.5,
    rank: 1,
    tags: ['AI', '编程助手', 'GitHub Copilot', 'ChatGPT'],
    publishedAt: Date.now() - 86400000, // 1天前
    trendingAt: Date.now() - 3600000, // 1小时前
  },
  {
    id: '2',
    title: '2024 年前端开发趋势预测',
    description: '分析 2024 年前端开发的主要趋势，包括框架演进、工具链发展和新技术应用。',
    url: 'https://example.com/frontend-trends-2024',
    thumbnail: 'https://images.unsplash.com/photo-1551650975-87deedd944c3?w=300&h=200&fit=crop',
    contentType: 'web',
    category: '前端开发',
    viewCount: 12680,
    shareCount: 654,
    likeCount: 1890,
    trendingScore: 0.91,
    growth: 189.3,
    rank: 2,
    tags: ['前端开发', '技术趋势', '2024', '预测'],
    publishedAt: Date.now() - 172800000, // 2天前
    trendingAt: Date.now() - 7200000, // 2小时前
  },
];

/**
 * 生成模拟搜索结果
 */
export function generateMockSearchResults(query: string, count = 10): SearchResult[] {
  return Array.from({ length: count }, (_, index) => ({
    id: `search_${Date.now()}_${index}`,
    title: `${query} - 搜索结果 ${index + 1}`,
    description: `这是关于 "${query}" 的搜索结果描述。包含了相关的技术信息、使用方法和最佳实践建议。`,
    url: `https://example.com/search-result-${index + 1}`,
    thumbnail: `https://images.unsplash.com/photo-${1500000000000 + index}?w=300&h=200&fit=crop`,
    publishDate: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000), // 随机30天内
    source: `示例网站 ${index + 1}`,
    contentType: ['web', 'image', 'video', 'news', 'document'][Math.floor(Math.random() * 5)] as ContentType,
    relevanceScore: 0.9 - index * 0.05,
    popularity: Math.floor(Math.random() * 10000) + 1000,
    rating: 4.0 + Math.random(),
    language: 'zh-CN',
    tags: [`${query}`, '相关标签', `标签${index + 1}`],
    highlights: {
      title: [query],
      description: [query, '相关内容'],
    },
  }));
}

/**
 * 生成模拟搜索建议
 */
export function generateMockSuggestions(query: string, count = 5): SearchSuggestion[] {
  const suggestions = [
    `${query} 教程`,
    `${query} 最佳实践`,
    `${query} 示例`,
    `${query} 文档`,
    `${query} 入门指南`,
    `${query} 高级技巧`,
    `${query} 常见问题`,
    `${query} 性能优化`,
  ];

  return suggestions.slice(0, count).map((text, index) => ({
    id: `suggestion_${Date.now()}_${index}`,
    text,
    type: 'suggestion' as const,
    frequency: Math.floor(Math.random() * 1000) + 100,
    category: '技术',
    metadata: {
      popularity: Math.floor(Math.random() * 100) + 50,
      resultCount: Math.floor(Math.random() * 5000) + 1000,
    },
  }));
}

/**
 * 延迟函数，用于模拟网络请求
 */
export function delay(ms: number): Promise<void> {
  return new Promise(resolve => setTimeout(resolve, ms));
}
